package org.cytoscape.myapp.cytoscape_app_v1.internal.tasks.groups;

import java.util.List;
import java.util.Set;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyEdge.Type;
import org.cytoscape.model.CyNode;
import org.cytoscape.myapp.cytoscape_app_v1.internal.model.StateCyGroups;
import org.cytoscape.work.FinishStatus;
import org.cytoscape.work.ObservableTask;
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.TaskObserver;

public class GroupCollapsedExpandTask implements Task,TaskObserver{

	private  CyApplicationManager appManager;
	private  CyGroupManager groupManager;
	private StateCyGroups state;
	private boolean isCompleted; 
	
	public GroupCollapsedExpandTask(CyApplicationManager appManager, CyGroupManager groupManager, StateCyGroups state){
		this.appManager =  appManager;
		this.groupManager = groupManager;
		this.state = state;
		this.isCompleted = false;
		
	}
	
	@Override
	public void run(TaskMonitor taskMonitor) throws Exception {
		taskMonitor.setTitle("Colapsando/Expandiendo");
		taskMonitor.setStatusMessage("Iniciando");
		Set<CyGroup> grupos = groupManager.getGroupSet(appManager.getCurrentNetwork());
		
		this.state.changeStateGroup(grupos);
		
		taskMonitor.setStatusMessage("Finalizando");
		
		
	}
	
	public void deleteEdge(CyNode node){
		List<CyEdge> edges = appManager.getCurrentNetwork().getConnectingEdgeList(node, node, Type.UNDIRECTED);
		appManager.getCurrentNetwork().removeEdges(edges);
	}
	
	public boolean isCompleted(){
		return this.isCompleted;
	}
	
	@Override
	public void cancel() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void taskFinished(ObservableTask task) {
		this.isCompleted = true;
		
	}
	
	
	@Override
	public void allFinished(FinishStatus finishStatus) {
		// TODO Auto-generated method stub
		
	}

}
